package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/6/16
 */
@RestController
@RequestMapping("tags")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping
    public List<Tag> getAll(){
      return  tagService.selectAll();
    }

    @PostMapping
    public Tag addTag(@RequestBody Tag tag){
        return tagService.addTag(tag);
    }

    @DeleteMapping("{id}")
    public void deleteTag(@PathVariable("id") Integer id){
        tagService.deleteById(id);
    }

    @GetMapping("{id}")
    public Tag getOneById(@PathVariable Integer id){
        Tag tag = tagService.getOne(id);
        return  tag;
    }

}
